const mongoose = require('mongoose');

const jobSchema = new mongoose.Schema({
  title: {
    type: String,
    required: [true, 'A job must have a title'],
    trim: true
  },
  company: {
    type: String,
    required: [true, 'A job must have a company name'],
    trim: true
  },
  location: {
    type: {
      type: String,
      default: 'Point',
      enum: ['Point']
    },
    coordinates: {
      type: [Number],
      required: true
    },
    address: String,
    city: String,
    state: String,
    country: String,
    zipCode: String
  },
  description: {
    type: String,
    required: [true, 'A job must have a description'],
    trim: true
  },
  requirements: [String],
  salary: {
    min: Number,
    max: Number,
    currency: {
      type: String,
      default: 'USD'
    }
  },
  jobType: {
    type: String,
    enum: ['Full-time', 'Part-time', 'Contract', 'Temporary', 'Internship', 'Remote'],
    required: [true, 'A job must have a type']
  },
  experienceLevel: {
    type: String,
    enum: ['Entry-level', 'Mid-level', 'Senior', 'Executive'],
    required: [true, 'A job must have an experience level']
  },
  postedDate: {
    type: Date,
    default: Date.now
  },
  deadline: Date,
  isActive: {
    type: Boolean,
    default: true
  },
  tags: [String],
  applicationUrl: String,
  companyLogo: String
});

// Create index for geospatial queries
jobSchema.index({ location: '2dsphere' });

// Create index for text search
jobSchema.index({
  title: 'text',
  company: 'text',
  description: 'text',
  requirements: 'text',
  tags: 'text'
});

const Job = mongoose.model('Job', jobSchema);

module.exports = Job; 